package com.arron.algorithm.leetcodetop100.技巧;

import java.util.Arrays;

public class 计数质数{



    public int countPrimes(int n) {

        boolean[] isPrime = new boolean[n];

        Arrays.fill(isPrime,true);

        for (int i = 2; i < n; i++) {
            if (isPrime[i]){
                for (int j = 2*i; j < n; j+=i) {
                    isPrime[j] = false;
                }
            }
        }

        int count =0;

        for (int i = 2; i < n; i++) {
            if (isPrime[i]) {
                System.out.println(i);
                count++;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        计数质数 a = new 计数质数();
        a.countPrimes(13);
    }





}
